package com.biaobiaoqi.scoreanalysis.administrator.action;

import javax.annotation.Resource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.biaobiaoqi.scoreanalysis.exception.DuplicateLoginNameException;
import com.biaobiaoqi.scoreanalysis.service.IAdministratorService;
import com.opensymphony.xwork2.ActionSupport;

public class AddAdmin extends ActionSupport {
	private static final Log log=LogFactory.getLog(AddAdmin.class);
	private String loginName;
	private String password;
	private String confirmPassword;
	private String userName;
	private String email;

	private static final long serialVersionUID = 6772842884803585290L;

	@Resource
	private IAdministratorService administratorService;

	public String execute() {
		try {
			if (!password.equals(confirmPassword)) {
				addActionError("两次密码输入不符！");
				return ERROR;
			}
			administratorService.addAdministrator(loginName, userName,
					password, email);
		} catch (DuplicateLoginNameException e) {
			log.debug("用户名已存在", e);
			addActionError("用户名已存在");
			return INPUT;
		} catch (Exception e) {
			log.error("服务器内部错误",e);
			addActionError("服务器内部错误");
			return ERROR;
		}
		return SUCCESS;
	}

	public IAdministratorService getAdministratorService() {
		return administratorService;
	}

	public void setAdministratorService(
			IAdministratorService administratorService) {
		this.administratorService = administratorService;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	public String getLoginName() {
		return loginName;
	}

	public void setLoginName(String loginName) {
		this.loginName = loginName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getConfirmPassword() {
		return confirmPassword;
	}

	public void setConfirmPassword(String confirmPassword) {
		this.confirmPassword = confirmPassword;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}
}
